package com.example.a28796.beautiful.styAdapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.example.a28796.beautiful.DoctorActivity;
import com.example.a28796.beautiful.HuodongActivity;
import com.example.a28796.beautiful.R;
import com.example.a28796.beautiful.stybean.FuliBean;

import java.util.List;

/**
 * Created by lenovo on 2016/8/30.
 */
public class ButtonAdapter extends RecyclerView.Adapter<ButtonAdapter.MyViewHolder> {
    private List<FuliBean.ObjBean.ModulesBean> mButtonData;
    private Context context;

    public ButtonAdapter(List<FuliBean.ObjBean.ModulesBean> mButtonData, Context context) {
        this.mButtonData = mButtonData;
        this.context = context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_button,null);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        FuliBean.ObjBean.ModulesBean modulesBean = mButtonData.get(position);
        holder.button.setTextSize(16);
        holder.button.setTextColor(Color.BLACK);
        holder.button.setText(modulesBean.getTitle());
        holder.button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(position==0){
                    context.startActivity(new Intent(context, HuodongActivity.class));
                }else if(position==1){
                    context.startActivity(new Intent(context, DoctorActivity.class));
                }else if(position==2){
                    context.startActivity(new Intent(context, MingxingActivity.class));
                }else if(position==3){

                }else if(position==4){

                }else if(position==5){

                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mButtonData==null?0:mButtonData.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder{
        private Button button;
        public MyViewHolder(View itemView) {
            super(itemView);
            button = (Button) itemView.findViewById(R.id.bt_item);
        }
    }
}
